
let oldArrayPropotype=Array.prototype

let arrayMethods=Object.create(oldArrayPropotype)

let methods=['push','unshift','shift','pop','sort','splice']

methods.forEach(method=>{
    
    arrayMethods[method]=function (...arg){
        let ob=this.__ob__
        oldArrayPropotype[method].apply(this,[...arg])
        let insert=null
        switch(method){
            case 'push':
            case 'unshift':
                insert=arg
                break
            case 'splice':
                insert=arg.slice(2)
                break
            default:
                break
        }
        //对于新增的数据如果是对象则也要变成响应式
        if(insert){
            ob.observeArray(insert)
        }
        ob.dep.notify()
    }
    
})

export default arrayMethods